<?php

namespace My\Controller;

class ModelHouseController extends ContentController {
	
	public function uploadImageAction() {
		$model = $this->getModel($this->catId);
		$this->setActionTitle("uploadImage", "上传图片");
		$condition = array(
				'this0.id' => $this->id 
		);
		$house = M()->table('__MODEL_HOUSE__ this0')->join("__MODEL_HOUSE_CONFIG__ this1 on this0.id=this1.id")->where($condition)->find();
		$this->checkAdmin($house['customer'] ? $house['customer'] : '-1');
		$this->resetHeader($model['unit']); // 导航重置
		$houseJSON = json_encode(unserialize($house['pic']));
		$this->assign("house", $house);
		$this->assign("houseJSON", $houseJSON ? $houseJSON : "[]");
		$this->display($this->getTemplete('house', 'uploadImage'));
	}
	
	// 文件上传
	public function uploadAction() {
		$upload = new \Utuo\Upload();
		$info = $upload->uploadOne();
		if (!$info) {
			$this->ajaxError($upload->getError());
		} else {
			$this->ajaxSuccess("上传成功", $info);
		}
	}
	
	
	// 预览场景
	public function previewAction() {
		$this->setActionTitle('preview', '预览效果');
		$configUrl = sprintf('http://%s%s',$_SERVER['HTTP_HOST'],__CONTROLLER__.'/getConfigXml/id/'.I('id',0,'intval').'/cat_id/'.$this->catId);
		$this->assign('configUrl',$configUrl);
		$this->display($this->getTemplete('house', 'preview'));
	}
	
	// 获取3d场景配置
	public function getConfigXmlAction() {
		$id = I('id', 0, 'intval');
		$pics = M('ModelHouseConfig')->where('id=%d', $id)->getField('pic');
		$pics = unserialize($pics);
		$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<panorama id="">
	<view fovmode="0" pannorth="0">
		<start pan="0" fov="70" tilt="0" />
		<min pan="0" fov="5" tilt="-90" />
		<max pan="360" fov="120" tilt="90" />
	</view>
	<userdata title="" datetime="" description=""
		copyright="" tags="" author="" source="" comment="" info="" longitude=""
		latitude="" />
	<hotspots width="180" height="20" wordwrap="1">
		<label width="180" backgroundalpha="1" enabled="1" height="20"
			backgroundcolor="0xffffff" bordercolor="0x000000" border="1"
			textcolor="0x000000" background="1" borderalpha="1" borderradius="1"
			wordwrap="1" textalpha="1" />
		<polystyle mode="0" backgroundalpha="0.2509803921568627"
			backgroundcolor="0x0000ff" bordercolor="0x0000ff" borderalpha="1" />
	</hotspots>
	<media />
	<input 
		tile0url="{$pics[1]}" 
		tile1url="{$pics[2]}"
		tile2url="{$pics[3]}" 
		tile3url="{$pics[4]}"
		tile4url="{$pics[0]}" 
		tile5url="{$pics[5]}"
		prev5url="images/1_o_preview_5.jpg"
		prev4url="images/1_o_preview_4.jpg" 
		prev3url="images/1_o_preview_3.jpg"
		prev2url="images/1_o_preview_2.jpg" 
		prev1url="images/1_o_preview_1.jpg"
		prev0url="images/1_o_preview_0.jpg" 
		tilesize="750" 
		tilescale="1.013333333333333"  />
	<control simulatemass="1" lockedmouse="0" lockedkeyboard="0"
		dblclickfullscreen="0" invertwheel="0" lockedwheel="0" invertcontrol="1"
		speedwheel="1" sensitivity="8" />
</panorama>
XML;
       header('Content-Type:text/xml; charset=utf-8');
       exit($xml);
	}
	
}

